package ar.edu.unicen.exa.isistan.archassis.view.cases.caseitem;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

import swing2swt.layout.BorderLayout;
import ar.edu.unicen.exa.isistan.archassis.ia.api.db.ListCases;
import ar.edu.unicen.exa.isistan.archassis.model.listeners.ICasesListener;

public class CaseComposite extends Composite {
	
	private static final Color BACKGROUND = SWTResourceManager.getColor(248, 248, 255);
	private Label caseNameLabel;
	
//	private Color selectedBGColor;
//	private Color selectedFGColor;
//	private Color unselectedBGColor;
//	private Color unselectedFGColor;
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public CaseComposite(Composite parent, int style) {
		super(parent, SWT.BORDER);
		setBackground(BACKGROUND);
		setLayout(new BorderLayout(0, 0));
		
		caseNameLabel = new Label(this, SWT.WRAP | SWT.RIGHT);

		caseNameLabel.setLayoutData(BorderLayout.NORTH);
		caseNameLabel.setText("Nombre del caso");
		caseNameLabel.setBackground(BACKGROUND);
		
		//Button btnUsar = new Button(this, SWT.NONE);
		Link link = new Link(this, SWT.NONE);
		link.setBackground(BACKGROUND);
		link.setLayoutData(BorderLayout.SOUTH);
		link.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("caso seleccionado!");
				selectThisCase();
			}
		});
		link.setText("<a>Usar</a>");
		
		description = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
		description.setLayoutData(BorderLayout.CENTER);
		
		caseCount = new Label(this, SWT.NONE);
		caseCount.setLayoutData(BorderLayout.WEST);
		caseCount.setText("-");
		
		
//		selectedBGColor = SWTResourceManager.getColor(SWT.COLOR_RED);
//		selectedFGColor = SWTResourceManager.getColor(SWT.COLOR_WHITE);
//		unselectedBGColor = caseNameLabel.getBackground();
//		unselectedFGColor = caseNameLabel.getForeground();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
	
	private ListCases listCases;
	
	public void setCase(ListCases aiResult) {
		this.listCases = aiResult;
		this.getCaseNameLabel().setText(aiResult.getName());
		this.getDescription().setText(aiResult.getDescripcion());
		this.getCaseCount().setText(Integer.toString(aiResult.getCases().size()));
	}
	
	protected Label getCaseNameLabel() {
		return caseNameLabel;
	}


	protected void selectThisCase() {
		this.listener.change(listCases);
	}
	private ICasesListener listener;
	private Text description;
	private Label caseCount;
	public void setCaseListener(ICasesListener l) {
		this.listener = l;
	}
	protected Text getDescription() {
		return description;
	}
	protected Label getCaseCount() {
		return caseCount;
	}
}